import 'package:flutter/material.dart';
import 'package:hi_common/util/logger.dart';

class HiProfileHeader extends StatefulWidget {
  final String face;
  final String name;
  final ScrollController controller;

  const HiProfileHeader(
      {super.key,
      required this.face,
      required this.name,
      required this.controller});

  @override
  State<StatefulWidget> createState() {
    return _HeaderState();
  }
}

class _HeaderState extends State<HiProfileHeader> {
  double _bottom = 30;
  double MIN_OFFSET = 55;

  @override
  void initState() {
    super.initState();
    widget.controller.addListener(() {
      var offset = widget.controller.offset;
      logger.i(offset);
      setState(() {
        if (offset < MIN_OFFSET) {
          _bottom = 30 - 30 * offset / MIN_OFFSET;
        }
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(left: 10, bottom: _bottom),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          CircleAvatar(
            backgroundImage: Image.network(widget.face).image,
          ),
          Padding(
              padding: const EdgeInsets.only(left: 10),
              child: Text(
                widget.name,
                style: const TextStyle(fontSize: 12, color: Colors.black),
              ))
        ],
      ),
    );
  }
}
